#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time   : 2021/3/28 20:10
# @Author : cjw
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support.select import Select
import time

if __name__ == '__main__':
    options = webdriver.ChromeOptions()
    options.add_experimental_option('excludeSwitches', ['enable-automation'])  # 不显示自动化软件控制提示
    options.add_argument('--headless')  # 无头化
    options.add_argument('--disable-gpu')  # 禁用gpu

    driver = webdriver.Chrome(options=options)
    driver.maximize_window()
    driver.get('https://www.endata.com.cn/BoxOffice/BO/Year/index.html')
    select_el = WebDriverWait(driver, 10).until(lambda x: x.find_element_by_xpath('//*[@id="OptionDate"]'))
    select = Select(select_el)
    # 让浏览器进行调整选项
    for i in range(len(select.options)):
        select.select_by_index(i)
        '//*[@id="TableList"]/table'
        table = WebDriverWait(driver, 10).until(lambda x: x.find_element_by_xpath('//*[@id="TableList"]/table'))
        print(table.text)
        print('-----------------------------------------------')

    # 如何拿到页面代码(经过数据加载以及js执行之后的结果的html内容)
    time.sleep(2)
    page_source = driver.page_source
    print(page_source)
    driver.quit()
